package com.zjm.principle.srp;

/**
 * 类的单一职责
 */
public class UserService1 {

    private final EmailValidator validator = new EmailValidator();
    private final UserSaver userSaver = new UserSaver();
    private final EmailSender emailSender = new EmailSender();

    public void registerUser(String email) {
        if (!validator.isValid(email)) {
            System.out.println("注册失败：邮箱格式错误");
            return;
        }

        userSaver.save(email);
        emailSender.sendWelcomeEmail(email);
    }
}

class EmailValidator {
    public boolean isValid(String email) {
        return email != null && email.contains("@");
    }
}

class UserSaver {
    public void save(String email) {
        System.out.println("保存用户: " + email);
    }
}

class EmailSender {
    public void sendWelcomeEmail(String email) {
        System.out.println("发送欢迎邮件到: " + email);
    }
}
